(function (e, t) {
  for (var a in t) {
    e[a] = t[a];
  }
})(exports, function (e) {
  var t = {};
  function a(n) {
    if (t[n]) {
      return t[n].exports;
    }
    var i = t[n] = {
      i: n,
      l: false,
      exports: {}
    };
    e[n].call(i.exports, i, i.exports, a);
    i.l = true;
    return i.exports;
  }
  a.m = e;
  a.c = t;
  a.d = function (e, t, n) {
    a.o(e, t) || Object.defineProperty(e, t, {
      configurable: false,
      enumerable: true,
      get: n
    });
  };
  a.r = function (e) {
    Object.defineProperty(e, "__esModule", {
      value: true
    });
  };
  a.n = function (e) {
    var t = e && e.__esModule ? function () {
      return e.default;
    } : function () {
      return e;
    };
    a.d(t, "a", t);
    return t;
  };
  a.o = function (e, t) {
    return Object.prototype.hasOwnProperty.call(e, t);
  };
  a.p = "";
  return a(a.s = 1);
}([function (e, t) {
  Object.defineProperty(t, "__esModule", {
    value: true
  });
  var a = function () {
    function e() {}
    e.lerr = function () {
      var e = [];
      for (var t = 0; t < arguments.length; t++) {
        e[t] = arguments[t];
      }
      e.unshift("====>");
      console.error.apply(window, e);
    };
    e.llog = function () {
      var e = [];
      for (var t = 0; t < arguments.length; t++) {
        e[t] = arguments[t];
      }
      e.unshift("====>");
      console.log.apply(window, e);
    };
    e.twoInt = function (e) {
      if (e < 10) {
        return "0" + e;
      } else {
        return e;
      }
    };
    e.todayStr = function () {
      var t = new Date();
      return "" + t.getFullYear() + e.twoInt(t.getMonth() + 1) + e.twoInt(t.getDate());
    };
    e.randomInt = function (e, t) {
      return Math.floor(Math.random() * (t - e + 1) + e);
    };
    e.saveData = function (e, t) {
      var a = window.localStorage;
      a && a.setItem("kcSdk_" + e, t);
    };
    e.loadData = function (e) {
      var t = window.localStorage;
      if (t) {
        var a = t.getItem("kcSdk_" + e);
        if (a) {
          return a;
        }
      }
      return null;
    };
    e.encodeUTF8 = function (e) {
      var t;
      var a;
      var n;
      var i = [];
      for (t = 0; t < e.length; t++) {
        if ((a = e.charCodeAt(t)) < 128) {
          i.push(a);
        } else if (a < 2048) {
          i.push(192 + (a >> 6 & 31), 128 + (63 & a));
        } else {
          if ((n = 55296 ^ a) >> 10 == 0) {
            a = (n << 10) + (56320 ^ e.charCodeAt(++t)) + 65536, i.push(240 + (a >> 18 & 7), 128 + (a >> 12 & 63));
          } else {
            i.push(224 + (a >> 12 & 15));
          }
          i.push(128 + (a >> 6 & 63), 128 + (63 & a));
        }
      }
      return i;
    };
    e.s = function (t) {
      var a;
      var n;
      var i;
      var s = new Uint8Array(e.encodeUTF8(t));
      var o = 16 + (s.length + 8 >>> 6 << 4);
      (t = new Uint8Array(o << 2)).set(new Uint8Array(s.buffer));
      t = new Uint32Array(t.buffer);
      i = new DataView(t.buffer);
      for (a = 0; a < o; a++) {
        t[a] = i.getUint32(a << 2);
      }
      t[s.length >> 2] |= 128 << 24 - 8 * (3 & s.length);
      t[o - 1] = s.length << 3;
      var l = [];
      var r = [function () {
        return h[1] & h[2] | ~h[1] & h[3];
      }, function () {
        return h[1] ^ h[2] ^ h[3];
      }, function () {
        return h[1] & h[2] | h[1] & h[3] | h[2] & h[3];
      }, function () {
        return h[1] ^ h[2] ^ h[3];
      }];
      var c = function c(e, t) {
        return e << t | e >>> 32 - t;
      };
      var d = [1518500249, 1859775393, -1894007588, -899497514];
      var h = [1732584193, -271733879, null, null, -1009589776];
      h[2] = ~h[0];
      h[3] = ~h[1];
      for (a = 0; a < t.length; a += 16) {
        var u = h.slice(0);
        for (n = 0; n < 80; n++) {
          l[n] = n < 16 ? t[a + n] : c(l[n - 3] ^ l[n - 8] ^ l[n - 14] ^ l[n - 16], 1);
          i = c(h[0], 5) + r[n / 20 | 0]() + h[4] + l[n] + d[n / 20 | 0] | 0;
          h[1] = c(h[1], 30);
          h.pop();
          h.unshift(i);
        }
        for (n = 0; n < 5; n++) {
          h[n] = h[n] + u[n] | 0;
        }
      }
      i = new DataView(new Uint32Array(h).buffer);
      for (a = 0; a < 5; a++) {
        h[a] = i.getUint32(a << 2);
      }
      return Array.prototype.map.call(new Uint8Array(new Uint32Array(h).buffer), function (e) {
        return (e < 16 ? "0" : "") + e.toString(16);
      }).join("");
    };
    e.b = function (e) {
      var t = [];
      for (var a in e) {
        t.push(a);
      }
      t = t.sort();
      var n = "";
      for (var i = 0; i < t.length; i++) {
        var s = e[t[i]];
        "object" == typeof s && (s = this.b(s));
        n += t[i] + s;
      }
      return n;
    };
    e.a = function (t, a, n) {
      var i = [];
      for (var s in t) {
        if (null !== t[s] && undefined !== t[s]) {
          i.push(s);
        } else {
          delete t[s];
        }
      }
      i = i.sort();
      var o = e.b(t);
      a && (o += a);
      o += n || "pH0Xhyenu2e1zdUg";
      return e.s(o);
    };
    e.jax = function (t, a, n) {
      n || (n = function n(t) {
        if (t) {
          return e.lerr(t);
        }
      });
      var i = new XMLHttpRequest();
      var s = new Date().getTime();
      a.s = e.a(a, s);
      i.open("POST", t, true);
      i.setRequestHeader("Content-Type", "application/json; charset=utf-8");
      i.setRequestHeader("ts", "" + s);
      var o = JSON.stringify(a);
      i.send(o);
      i.onload = function () {
        if (200 == i.status) {
          var t = {
            jaxERR: "" + i.responseText
          };
          try {
            t = JSON.parse(i.responseText);
          } catch (t) {
            e.lerr(t);
            return n(null, {
              re: "1111",
              err: "jsonErr:" + i.responseText
            });
          }
          return n(null, t);
        }
        return n(null, {
          re: "9" + i.status
        });
      };
    };
    return e;
  }();
  t.jax = a.jax;
  t.llog = a.llog;
  t.lerr = a.lerr;
  t.saveData = a.saveData;
  t.loadData = a.loadData;
  t.randomInt = a.randomInt;
  t.todayStr = a.todayStr;
}, function (e, t, a) {
  Object.defineProperty(t, "__esModule", {
    value: true
  });
  var n = a(0);
  var i = function () {
    function e() {
      this.version = "203";
      this.jumpGap = 3e3;
      this.lastJumpT = 0;
      this.htHost = "https://dk.gametdd.com/htApi/ht_api/";
      this.picType = "jpg";
      this.stageTime = 0;
    }
    e.instance = function () {
      if (e.me) {
        return e.me;
      } else {
        return e.me = new e(), e.me;
      }
    };
    e.prototype.getUid = function () {
      if (e.Uid) {
        return e.Uid;
      } else {
        return e.Uid = n.loadData("uid"), e.Uid || "null";
      }
    };
    e.prototype.getOpenId = function () {
      if (e.openId) {
        return e.openId;
      } else {
        return e.openId = n.loadData("openId"), e.openId || "null";
      }
    };
    e.prototype.setUid = function (t) {
      if (t) {
        e.Uid = t;
        n.saveData("uid", t);
      }
    };
    e.prototype.setOpenId = function (t) {
      if (t) {
        e.openId = t;
        n.saveData("openId", t);
      }
    };
    e.prototype.jht = function (t, a, i) {
      if (e.Gid) {
        a.v = this.version;
        n.jax(this.htHost + t, a, function (e, t) {
          if (e || !t) {
            return n.llog("jhtERR", e), i(e || new Error("no re"));
          } else {
            if (0 !== t.re) {
              return n.llog("jht FAILED!" + JSON.stringify(t)), i(new Error("err:" + t.re));
            } else {
              return void i(null, t);
            }
          }
        });
      } else {
        n.llog("htSdk 未初始化!!jht");
      }
    };
    e.prototype.init = function (t, a, i) {
      var s = this;
      n.llog("HTS init v:" + this.version + "," + t + "," + !!a);
      if (!t) {
        n.llog("HTS no gid.");
        return i(new Error("htSdk 无gid"));
      }
      e.Gid = t;
      var o = n.loadData("htHost");
      o && (this.htHost = o);
      var l = n.loadData("picType");
      l && (this.picType = l);
      var r = {
        gid: t,
        uid: this.getUid(),
        openId: this.getOpenId()
      };
      n.llog("hts init start..." + this.picType + "," + this.htHost);
      this.jht("init2", r, function (t, o) {
        if (t) {
          i(t);
        } else {
          n.llog("hts init done:" + o.re);
          s.setUid(o.uid);
          o.iconPre && (e.IconPre = o.iconPre);
          if (o.picType) {
            s.picType = o.picType, n.saveData("picType", o.picType);
          }
          o.jumpGap && (s.jumpGap = o.jumpGap);
          i(null, "ok");
          if (o.htHost && o.htHost !== s.htHost) {
            s.htHost = o.htHost, n.saveData("htHost", o.htHost);
          }
          a || (a = window.wx);
        }
      });
    };
    e.prototype.getBox = function (t, a) {
      var i = this;
      if (!e.IconPre || !e.Gid) {
        n.llog("htSdk 未初始化!!" + e.IconPre);
        return a(new Error("htSdk 未初始化 getBox"));
      }
      var s = {
        bid: t
      };
      this.jht("getBox", s, function (n, s) {
        if (n) {
          return a(n);
        }
        if (0 !== s.re || !s.arr) {
          return a(new Error("服务配置有误bid:" + t + ",re:" + s.re));
        }
        var o = [];
        for (var l = 0; l < s.arr.length; l++) {
          var r = s.arr[l];
          var c = [];
          for (var d = 0; d < r.length; d++) {
            var h = r[d].split("@");
            var u = "";
            var g = "";
            h.length >= 4 && "0" !== h[3] && (u = "_" + h[3]);
            h.length >= 5 && (g = h[4]);
            c.push({
              jumpKey: h[1],
              mid: h[0],
              iconUrl: e.IconPre + h[0] + u + "." + i.picType,
              txt: h[2],
              mark: g
            });
          }
          o.push(c);
        }
        a(null, o);
      });
    };
    e.prototype.jumpTo = function (t, a, i) {
      var s = this;
      if (e.Gid) {
        var o = new Date().getTime();
        if (o - this.lastJumpT < this.jumpGap) {
          n.llog("jumpTo too");
        } else {
          this.lastJumpT = o;
          var l = {
            gid: e.Gid,
            uid: this.getUid(),
            bid: t,
            mid: a
          };
          if (t) {
            if (a) {
              i && (l.fail = "true");
              n.llog("jumpTo", JSON.stringify(l));
              this.jht("jumpTo", l, function (e, t) {
                e || s.setUid(t.uid);
              });
            } else {
              n.llog("jumpTo 无mid");
            }
          } else {
            n.llog("jumpTo 无bid");
          }
        }
      } else {
        n.llog("htSdk 未初始化!! jumpTo");
      }
    };
    e.prototype.jumpFail = function (e, t) {
      this.jumpTo(e, t, true);
    };
    e.prototype.navigateToMiniProgram = function (t, a) {
      if (e.Gid) {
        a || (a = window.wx);
        if (a) {
          var i = "hts_gid=" + e.Gid;
          var s = n.loadData("hts_link");
          s && s.length > 5 && (i += "&hts_link=" + s);
          if (t.path && t.path.length > 0) {
            t.path += "&" + i;
          } else {
            t.path = "?" + i;
          }
          a.navigateToMiniProgram(t);
        } else {
          n.llog("navigateToMiniProgram 无channelObj");
        }
      } else {
        n.llog("htSdk 未初始化!!navigateToMiniProgram");
      }
    };
    e.prototype.jumpFrom = function (t) {
      var a = this;
      if (e.Gid) {
        if (t) {
          n.llog("query", t);
          if (t.hts_gid) {
            var i = {
              query: t,
              gid: e.Gid,
              uid: this.getUid(),
              openId: this.getOpenId()
            };
            n.llog("jumpFrom", JSON.stringify(i));
            this.jht("jumpFrom", i, function (e, t) {
              if (!e) {
                t.hts_link && n.saveData("hts_link", t.hts_link);
                t.uid && a.setUid(t.uid);
              }
            });
          } else {
            n.llog("jumpFrom no hts_gid:", t);
          }
        } else {
          n.llog("jumpFrom query is empty!", t);
        }
      } else {
        n.llog("htSdk 未初始化!!jumpFrom");
      }
    };
    e.prototype.bindOpenId = function (t, a) {
      this.jht("bindOpenId", {
        openId: t,
        gid: e.Gid,
        uid: this.getUid()
      }, a);
      this.setOpenId(t);
    };
    e.prototype.codeForOpenId = function (t, a) {
      var i = this;
      this.jht("codeForOpenId", {
        code: t,
        uid: this.getUid(),
        gid: e.Gid
      }, function (e, t) {
        if (e) {
          n.lerr(e);
          return a(e);
        }
        if (t.data) {
          t.data.openid && i.setOpenId(t.data.openid);
          a(null, t.data);
        } else {
          a();
        }
        t.uid && i.setUid(t.uid);
      });
    };
    e.prototype.stageLog = function (t, a, i, s) {
      var o = {
        eventName: t,
        stageId: a,
        openId: this.getOpenId(),
        gid: e.Gid,
        uid: this.getUid(),
        userProps: i
      };
      s && (o.stageTime = s);
      this.jht("stageLog", o, function (e) {
        if (e) {
          return n.lerr(e);
        }
      });
    };
    e.prototype.stageStart = function (e, t) {
      this.stageTime = 0;
      this.stageLog("start", e, t);
    };
    e.prototype.stageFail = function (e, t) {
      this.stageTime = Date.now() - this.stageTime;
      this.stageLog("fail", e, t, this.stageTime);
      this.stageTime = 0;
    };
    e.prototype.stageComplet = function (e, t) {
      this.stageTime = Date.now() - this.stageTime;
      this.stageLog("complet", e, t, this.stageTime);
      this.stageTime = 0;
    };
    e.prototype.userUpdate = function (t) {
      this.jht("userUpdate", {
        openId: this.getOpenId(),
        gid: e.Gid,
        uid: this.getUid(),
        userProps: t
      }, function (e) {
        if (e) {
          return n.lerr(e);
        }
      });
    };
    e.prototype.eventReport = function (t, a, i) {
      this.jht("eventReport", {
        eventName: t,
        eventProp: a,
        openId: this.getOpenId(),
        gid: e.Gid,
        uid: this.getUid(),
        userProps: i
      }, function (e) {
        if (e) {
          return n.lerr(e);
        }
      });
    };
    e.prototype.sceneReport = function (t, a, i) {
      this.jht("sceneReport", {
        sceneName: t,
        sceneTime: a,
        openId: this.getOpenId(),
        gid: e.Gid,
        uid: this.getUid(),
        userProps: i
      }, function (e) {
        if (e) {
          return n.lerr(e);
        }
      });
    };
    e.prototype.getSharePic = function (e, t) {
      this.jht("getSharePic", {
        game: e
      }, t);
    };
    e.prototype.shareTo = function (e) {
      this.jht("shareTo", {
        wxPicId: e
      }, function (t) {
        if (t) {
          n.lerr(t);
        } else {
          n.llog("shareTo OK," + e);
        }
      });
    };
    e.prototype.shareFrom = function (e) {
      this.jht("shareFrom", {
        wxPicId: e
      }, function (t) {
        if (t) {
          n.lerr(t);
        } else {
          n.llog("shareFrom OK," + e);
        }
      });
    };
    e.prototype.jreq = function (e, t, a) {
      n.jax(e, t, a);
    };
    return e;
  }();
  t.default = i.instance();
}]));